package com.cms.chris.controller;

import com.alibaba.fastjson.JSON;
import com.cms.chris.service.ColumnService;
import com.common.chris.entity.R;
import com.github.pagehelper.PageInfo;
import com.sdk.chris.usersdk.dto.UserDTO;
import com.sdk.chris.usersdk.feign.UserTestFeignClient;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/cms")
public class CmsTestController {

    @Autowired
    private UserTestFeignClient userTestFeignClient;

    @Autowired
    private ColumnService columnService;

    @Autowired
    private Test001 test001;

    @Value("${hehe}")
    private String hehe;

    @GetMapping("/list/user")
    public R<PageInfo<UserDTO>> aaa() {
        R<PageInfo<UserDTO>> s = userTestFeignClient.listUser();
        log.info("返回结果是-{}", JSON.toJSONString(s));
        System.out.println(s);
        return s;
    }


    @GetMapping("/test01")
    public String test01() {
        String s = test001.test01();
        System.out.println(s);
        return "hello";
    }


    @GetMapping("/test02")
    @GlobalTransactional
    public String test02() {
        columnService.add();
        R<Integer> add = userTestFeignClient.add();
        log.info("--------------{}", JSON.toJSONString(add));
        return "success";
    }

    @GetMapping("/test03")
    public String test03() {
        System.out.println(hehe);
        return hehe;
    }


    @GetMapping("/test04")
    @GlobalTransactional
    public String test04() {
        columnService.add();
        Integer integer = test001.test02();
        log.info("--------------{}", JSON.toJSONString(integer));
        return "success";
    }

}
